package example

import "gitee.com/youbeiwuhuan/gin-practice/go-enums/emums"

var animalsEnumMap map[int]string

type animalsEnumDef struct {
	Dog, Monkey, Lion int
}

func (c animalsEnumDef) Description() string {
	return "动物枚举"
}

// Values  返回一个包含所有枚举值的切片
func (c animalsEnumDef) Values() []int {
	return []int{c.Dog, c.Monkey, c.Lion}
}

// EnumItems 返回一个包含所有枚举值的切片
func (c animalsEnumDef) EnumItems() []emums.EnumItem[int] {
	sl := make([]emums.EnumItem[int], len(animalsEnumMap), len(animalsEnumMap))
	for k, v := range animalsEnumMap {
		sl = append(sl, emums.EnumItem[int]{Val: k, Label: v})
	}
	return sl
}

// Check 检查val是否枚举中一项
func (c animalsEnumDef) Check(val int) bool {
	_, ok := animalsEnumMap[val]
	return ok
}

// GetLabel  由val获取枚举值的描述
func (c animalsEnumDef) GetLabel(val int) (string, bool) {
	value, ok := animalsEnumMap[val]
	return value, ok
}

// ValueOf 根据名称返回对应的枚举值
func (c animalsEnumDef) ValueOf(label string) (int, bool) {
	for k, v := range animalsEnumMap {
		if v == label {
			return k, true
		}
	}

	return 0, false
}

var AnimalsEnum = animalsEnumDef{
	Dog:    12,
	Monkey: 107,
	Lion:   114,
}

func init() {
	//animalsEnumMap = make(map[int]string)
	//animalsEnumMap[AnimalsEnum.Dog] = "狗"
	//animalsEnumMap[AnimalsEnum.Monkey] = "猴子"
	//animalsEnumMap[AnimalsEnum.Lion] = "狮子"
	animalsEnumMap = map[int]string{
		12:  "狗",
		107: "猴子",
		114: "狮子",
	}

	//emums.RegistEnum[int]("AnimalsEnum", AnimalsEnum)
}
